<!DOCTYPE html>
<html class="x-admin-sm">

	<head>
		<meta charset="UTF-8">
		<title>欢迎页面-X-admin2.2</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="stylesheet" href="./css/font.css">
		<link rel="stylesheet" href="./css/xadmin.css">
		<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="./js/xadmin.js"></script>
		<style>
			.wi{
				width: 300px;
			}
		</style>
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row" id="app">
				<form class="layui-form">
					<div class="layui-form-item">
						<label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>推荐名称</label>
						<div class="layui-input-inline">
							<input type="text" :value="webCour.name" id="name" name="recname" required="" lay-verify="nikename" autocomplete="off" class="layui-input">
						</div>
					</div>
					
					<div class="layui-form-item">
						<label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>更多跳转</label>
						<div class="layui-input-inline">
							<input type="text" :value="webCour.link" id="link" name="reclink" required="" lay-verify="nikename" autocomplete="off" class="layui-input">
						</div>
					</div>
					
					<div class="layui-form-item">
						<label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>详细描述</label>
						<div class="layui-input-inline">
							<input type="text" :value="webCour.description" id="description" name="description" required="" lay-verify="nikename" autocomplete="off" class="layui-input wi">
						</div>
					</div>
					
					<div class="layui-form-item">
						<label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>最大限制数量</label>
						<div class="layui-input-inline">
							<input type="text" :value="webCour.coursenum" id="coursenum" name="coursenum" required="" lay-verify="nikename" autocomplete="off" class="layui-input">
						</div>
					</div>
					
					<div class="layui-form-item">
						<label for="L_repass" class="layui-form-label"></label>
						<button class="layui-btn" lay-filter="add" lay-submit="">提交</button></div>
				</form>
			</div>
		</div>
		<script type="text/javascript" src="./js/jquery.min.js"></script>
		<script src="./js/vue.min.js"></script>
		<script type="text/javascript" src="js/vue.js"></script>
		<script src="js/axios.min.js"></script>
		<script type="text/javascript" src="js/jquery.cookie.js"></script>
		<script>
			var recId = $.cookie("recId");
			const app = new Vue({
				el: "#app",
				data: {
					webCour: []
				},
				methods: {

				},
				created() {
					let _this = this;
					$.ajax({
						type:"get",
						url:"http://localhost:9095/admin/websiteCourse/getById",
						async:true,
						data:{
							"id": recId
						},
						headers: {
							"token2": $.cookie("token2")
						},
						success: function(response){
							console.log(response.data);
							_this.webCour = response.data;
						}
					});
//					$.get("http://localhost:9095/admin/websiteCourse/getById", {
//						"id": recId
//					}).then(function(response) {
//						console.log(response.data);
//						_this.webCour = response.data;
//					});
				}
			});
			
			layui.use(['form', 'layer'],
				function() {
					$ = layui.jquery;
					var form = layui.form,
						layer = layui.layer;

					//监听提交
					form.on('submit(add)',
						function(data) {
							axios.defaults.headers.common["token2"] = $.cookie("token2");
							var websiteCourse = new URLSearchParams();
							websiteCourse.append("id", recId);
							websiteCourse.append("name", $("#name").val());
							websiteCourse.append("link", $("#link").val());
							websiteCourse.append("description", $("#description").val());
							websiteCourse.append("coursenum", $("#coursenum").val());
							axios({
								method: "post",
								url: "http://localhost:9095/admin/websiteCourse/upRec",
								headers:{
									'Content-Type':'application/x-www-form-urlencoded'
								},
								params: websiteCourse
							}).then(function(res){
								var msg = res.data;
								console.log(msg)
								if (msg.code==10100){//与当前已有数据不匹配
									//提示信息
									layer.alert(msg.message, {
										icon: 5,
										title: '提示'
									});
								} else if(msg.code==200){
									layer.alert("修改成功", {
									icon: 6
									},
									function() {
										//刷新父窗口
										window.parent.location.reload();
										// 获得frame索引
										var index = parent.layer.getFrameIndex(window.name);
										//关闭当前frame
										parent.layer.close(index);
									});
								} else {
									//提示信息
									layer.alert('修改失败！', {
										icon: 5,
										title: '提示'
									});
								}
						})
						return false;
					});
				});
		</script>
		<script>
			var _hmt = _hmt || [];
			(function() {
				var hm = document.createElement("script");
				hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
				var s = document.getElementsByTagName("script")[0];
				s.parentNode.insertBefore(hm, s);
			})();
		</script>
	</body>

</html>